package com.yutel.year;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;

public class TestYear {

	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
	private static Calendar c = Calendar.getInstance();
	private static StringBuffer sb = new StringBuffer();
	private static StringBuffer sbTemp = new StringBuffer();

	public static void main(String[] args) {
		try {
			long startTime = System.currentTimeMillis();
			Date startDay = sdf.parse("10000101");
			Date nextDay = startDay;
			for (int i = 0; i < 365 * 8800; i++) {
				c.setTime(nextDay);
				c.add(Calendar.DATE, 1);
				nextDay = c.getTime();
				duicheng(nextDay);
			}
			long endTime = System.currentTimeMillis();
			System.out.println("total time=" + ((endTime - startTime) / 1000));
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	public static boolean duicheng(Date d) {
		sb.delete(0, sb.length());
		sbTemp.delete(0, sbTemp.length());
		sb.append(sdf.format(d));
		for (int i = sb.length() - 1; i >= 0; i--) {
			sbTemp.append(sb.charAt(i));
		}
		if (sb.equals(sbTemp)) {
			System.out.println(sb.toString());
			return true;
		} else {
			return false;
		}
	}
}
